package com.bpz.main.directive;


import freemarker.template.TemplateMethodModelEx;
import freemarker.template.TemplateModelException;

import java.util.List;

/**
 * Created by 半瓶子 on 2/11/15.
 * blog: xusir.cnblogs.com
 */
public class PageCount implements TemplateMethodModelEx {

    @Override
    public Object exec(List args) throws TemplateModelException {
        Integer totalCount = 0;
        Integer pageSize = 0;
        try {
            totalCount = Integer.parseInt((String) args.get(0));
            pageSize = Integer.parseInt((String) args.get(1));
        } catch (NumberFormatException e) {
            throw new TemplateModelException("请输入正确的总记录数和页面记录数");
        }
        Integer pageCount = totalCount / pageSize
                + (totalCount % pageSize == 0 ? 0 : 1);
        return pageCount;
    }

}

